package org.example.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class NettyClientHandler extends ChannelInboundHandlerAdapter {

    private int index = 0;

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object s) throws Exception {

    }


    /**
     * 管道已准备就绪，发生给服务端
     *
     * @param ctx
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        StringBuffer sub = new StringBuffer();

        for (int i = 0; i < 100; i++) {
            sub.append("= \"file:///D:/pdf/1.netty%E5%BD%95%E6%92%AD%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/netty%E5%BD%95%E6%92%AD%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/03NIO%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E6%A1%86%E6%9E%B6Netty.pdf\";");
            if (i % 5 == 0) {
                String property = System.getProperty("line.separator");
                sub.append(property);
            }
        }
        ctx.channel().writeAndFlush(sub.toString());

    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable casue) {
        casue.printStackTrace();
        ctx.close();
    }
}
